package com.atguigu.service.impl;

import com.atguigu.bean.User;
import com.atguigu.dao.UserDao;
import com.atguigu.service.Userservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: liuaojun
 * @CreateTime: 2025-01-17
 * @Description:
 * @Version: 1.0
 */@Service
public class UserserviceImpl implements Userservice {
     @Autowired
     private UserDao userDao;


    @Override
    @Transactional(timeout = 3)
    public void updatePasswordAndNickname(User user) {
        userDao.UpdateUserPassword(user.getPassword(),user.getUsername());
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        userDao.UpdateUserNickName(user.getNickname(),user.getUsername());
        int i=1/0;
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW,noRollbackFor = ArithmeticException.class)
    @Override
    public void updatePassword(User user) {

        userDao.UpdateUserPassword(user.getPassword(),user.getUsername());
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void updateNickname(User user) {
        int i=1/0;
        userDao.UpdateUserNickName(user.getNickname(),user.getUsername());
    }


}
